/*******************************************************************************
* Copyright (C) 2019 China Micro Semiconductor Limited Company. All Rights Reserved.
*
* This software is owned and published by:
* CMS LLC, No 2609-10, Taurus Plaza, TaoyuanRoad, NanshanDistrict, Shenzhen, China.
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with CMS
* components. This software is licensed by CMS to be adapted only
* for use in systems utilizing CMS components. CMS shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. CMS is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/*****************************************************************************/
/** \file main.h
**
** 
**
** History:
** 
*****************************************************************************/
#ifndef __USER_INPUT_H__
#define __USER_INPUT_H__
/*****************************************************************************/
/* Include files */
/*****************************************************************************/

#include "main.h"


/*****************************************************************************/
/* Global pre-processor symbols/macros ('#define') */
/*****************************************************************************/



/*****************************************************************************/
/* Global variable declarations ('extern', definition in C source) */
/*****************************************************************************/


/*****************************************************************************/
/* Global function prototypes ('extern', definition in C source) */
/*****************************************************************************/


/*****************************************************************************/
/* Global type definitions ('typedef') */
/*****************************************************************************/

typedef union
{
	uint32_t  Word;
	struct
	{
		uint32_t gPowerKeyStatus:1;
		uint32_t gTriggerStatus:1;
		uint32_t gHspStatus:1;
		
		uint32_t gSspStatus:1;	
		uint32_t gPowerKeyHoldOn:1;
		uint32_t gDirStatus:1;
		uint32_t gSpnKeyStatus:1;
		/**/		
	
		uint32_t gTriggerRepeatDeal:1;
		uint32_t gTriggerHoldDeal:1;
		
		
		uint32_t gP2Status:1;     //P2 position	
		uint32_t gP1Status:1;     //P1 position		
		uint32_t gP0Status:1;
		uint32_t gTrgStatus:1;
		uint32_t gPosGetToStatus:1;

		uint32_t gCutHand:1;

		
		
    		/**/
   	 }bits;
}SENSOR_FLAG_UNION;


typedef struct 
{
	SENSOR_FLAG_UNION sensorFlag;
	ERROR_FLAG_UNION ErrorFlag;

	uint32_t batteryVoltagemV;
	uint32_t busAvgCurrentmA;
	uint32_t busPeakCurrentmA;
	
	uint16_t triggerAdc;
	uint16_t batteryVoltageADC;
	uint16_t busPeakCurrentAdc;
	uint16_t busAvgCurrentAdc;
	uint16_t ntc1Adc;
	uint16_t ntc2Adc;
	
	
	uint8_t PackSocStatus;
	float scaleADCtoMV;
	
	uint32_t speedNow;
	uint8_t speedLSP_Flag;
	
	
	uint8_t speedLevel;
	uint8_t superSpeedEn;
	uint16_t CntSignalHigh;
	uint8_t BatTemp;
	uint8_t BatSdata;
	uint8_t BatPdata;

	uint16_t StaVoltmV;
	uint16_t SuvpTimeMs;
	
	uint16_t OverVoltmV;
	uint16_t OvpTimeMs;
	
	uint16_t UnderVolt1mV;
	uint16_t Uvp1TimeMs;

	uint16_t UnderVolt2mV;
	uint16_t Uvp2TimeMs;
	
	uint16_t OtpAdc1P;
	uint16_t OtpTime1Ms;
	uint16_t OtpAdc1R;
	
	uint16_t OtpAdc2P;
	uint16_t OtpTime2Ms;
	uint16_t OtpAdc2R;
	
	uint16_t LowSpeedRpm;
	uint16_t LsptimeMs;
	uint32_t OppmA1;
	uint32_t OcpmA1;
	uint32_t OcpmA2;
	uint32_t OcpmA3;
	uint32_t OcpmA4;
	uint16_t OcpADC1;
	uint16_t OcpADC2;
	uint16_t OcpADC3;
	uint16_t OcpADC4;
	uint16_t OcpTimeMs1;
	uint16_t OcpTimeMs2;
	uint16_t OcpTimeMs3;
	uint16_t OcpTimeMs4;
	uint16_t OppTimeMs1;

	uint16_t lowLevel;
	uint16_t highLevel;
}SEN_STR;



extern SEN_STR strInput;

/*Functions*/
void UI_Init_Variables(void);
void UI_Get_Key_Status(void);
void UI_Get_Trigger_Status(void);
void UI_Get_Bus_Volt(void);
void UI_Get_Temperature(void);
void UI_Get_Bus_Curt(void);





#endif /* __USER_INPUT_H__ */
